import hashlib
import os

'''获取文件md5值'''
def calcsha1(path):
    with open(path, "rb") as ff:
        sha1obj = hashlib.sha1()
        sha1obj.update(ff.read())
        hash = sha1obj.hexdigest()
        print(hash)
        return hash


def calcMD5(path):
    with open(path, "rb") as ff:
        md5obj = hashlib.md5()
        md5obj.update(ff.read())
        hash = md5obj.hexdigest()
        print(hash)
        return hash


if __name__ == "__main__":
    count = 0
    for dirpath, dirnames, filenames in os.walk(r"E:\bilibilivideobypy"):
        for filename in filenames:
            count += 1
            filepath = os.path.join(dirpath, filename)
            print(filepath)
            calcMD5(filepath)
    print(count)